// 实现这个项目的构建任务
const sass = require("sass");
const loadGruntTasks = require("load-grunt-tasks");

module.exports = (grunt) => {
  grunt.initConfig({
    //   处理sass
    sass: {
      options: {
        implementation: sass,
      },
      main: {
        files: {
          "dist/assets/styles/main.scss": "src/assets/styles/main.scss",
        },
      },
    },
    // 压缩css
    cssmin:{
        main:{
            files:{
          "dist/assets/styles/main.scss": ["dist/assets/styles/main.scss"],

            }
        }
    },
    // 处理js
    babel: {
      options: {
        presets: ["@babel/preset-env"],
      },
      main: {
        files: {
          "dist/assets/scripts/main.js": "src/assets/scripts/main.js",
        },
      },
    },
    // 压缩js
    uglify:{
        main:{
            files:{
          "dist/assets/scripts/main.js": ["dist/assets/scripts/main.js"],
                
            }
        }
    },
    // 监视文件变化
    watch: {
      js: {
        files: ["src/assets/scripts/main.js"],
        tasks: ["babel"],
      },
      css: {
        files: ["src/assets/styles/*.scss"],
        tasks: ["sass"],
      },
    },
    // 清除构建文件
    clean: {
      dist: "dist/**",
    },
    // 复制文件
    copy: {
      main: {
        expand: true,
        src: "public/*",
        dest: "dist/",
      },
    },
  });
  // grunt.loadNpmTasks('grunt-sass')
  loadGruntTasks(grunt); //自动加载所有的 grunt 插件中的任务

  grunt.registerTask("deploy", ["sass","babel","watch"]); //启动的时候先执行一下单独任务，然后再启动监视操作
  grunt.registerTask('build',["clean","sass","cssmin","babel", "uglify","copy"])
  
};
